package com.eshop.modules.quartz.config;

import com.eshop.modules.quartz.domain.QuartzJob;
import java.util.List;
import java.util.function.Consumer;
import org.springframework.boot.ApplicationArguments;
import com.eshop.modules.quartz.utils.QuartzManage;
import com.eshop.modules.quartz.service.QuartzJobService;
import org.springframework.stereotype.Component;
import org.springframework.boot.ApplicationRunner;

@Component
public class JobRunner implements ApplicationRunner
{
    private final QuartzJobService quartzJobService;
    private final QuartzManage quartzManage;
    
    public JobRunner(final QuartzJobService quartzJobService, final QuartzManage quartzManage) {
        this.quartzJobService = quartzJobService;
        this.quartzManage = quartzManage;
    }
    
    public void run(final ApplicationArguments applicationArguments) {
        System.out.println("--------------------注入定时任务---------------------");
        final List<QuartzJob> quartzJobs = this.quartzJobService.findByIsPauseIsFalse();
        quartzJobs.forEach(this.quartzManage::addJob);
        System.out.println("--------------------定时任务注入完成---------------------");
    }
}
